package com.xy.demo.controller;

import com.xy.demo.DesignMode.AdapterPattern.*;
import com.xy.demo.Util.ResultUtil;
import com.xy.demo.Util.Util;
import com.xy.demo.model.ResultInfo;
import com.xy.demo.thread.CommonExecutor;
import com.xy.demo.thread.ThreadForAutoExecuteRun;
import com.xy.demo.thread.ThreadRun;
import org.slf4j.Logger;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @BelongsProject: bill
 * @BelongsPackage: com.xy.demo.controller
 * @Author: YangHao
 * @CreateTime: 2023-08-07  14:01
 * @Description: 设计模式
 * @Version: 1.0
 */
@RequestMapping("/design")
@RestController
public class DesignController {


    public static void main(String[] args) {
        StringReader stringReader = new StringReader(args[0]);
    }


    /**
     * @description: 适配器模式
     * @author: yang
     * @date: 2023/8/7 14:03
     * @param:
     * @return:
     **/
    @RequestMapping("/adapter")
    private ResultInfo AdapterController(){
        Target target = new ConcreteTarget();
        target.request();

        //类适配器
        Target adapterTarget = new AdapterClass();
        adapterTarget.request();

        //对象适配器
        Target adapterTarget2 = new AdapterObject();
        adapterTarget2.request();

        return   ResultUtil.getResultInfoOk("AdapterPattern");
    }

    /**
     * @description: 适配器模式 220V==>5V 适配器模式已知一个类AdapteeOne 稳定输出220V电压 这个类可能已经很多地方在用,现在需要输出一个5V的电压来用于充电(接口TargetOne),适配器将220V==>5V
     * 对象适配器：直接实现目标接口，实例化适配者，处理适配者   类适配器：继承适配者实现目标接口
     * @author: yang
     * @date: 2023/8/7 14:35
     * @param:
     * @return:
     **/
    @RequestMapping("/adapterOne")
    private ResultInfo AdapterOneController(){
        //对象适配器
        TargetOne targetOne = new AdapterObjectOne();
        int output = targetOne.outputDC5V();

        //类适配器
        TargetOne targetOne1 = new AdapterClassOne();
        targetOne1.outputDC5V();

        return  ResultUtil.getResultInfoOk("输出电压："+output+"V");
    }


}
